// posts_view.js

import React from "react";
import { Link } from 'react-router-dom';
import PostItem from './post_item';

class PostsView extends React.Component {
    render() {
        const { posts } = this.props;
        if (!posts || !posts.map) {
            return (<ul></ul>);
        }
        return (
            <ul>
                {posts !== null ? (posts.map(item => (
                    <Link key={item.post_id} to={`/posts/${item.post_id}`}>
                        <PostItem post={item} />
                    </Link>
                ))) : null}
            </ul>
        );
    }
}

export default PostsView;
